﻿/**
 * 
 * Copyright 2009, 2010 Mike Jamer [email: mikejamer@gmail.com ]
 * 
 * This File is part of Moose IRC
 * 
 * MooseIRC is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * MooseIRC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with MooseIRC.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using moose.irc.extension;

namespace moose.irc.actions.commands {

    /// <summary>
    /// Handles outgoing Private Messages
    /// </summary>
    [CLSCompliant(true)]
    [Action(Type = ActionTypes.Command,
        Name = "moose-std-cmd-privmsg",
        Description = "Handles Outgoing private messages the same way we handle incomming",
        Version = "0.1",
        Author = "Mike MacKenzie-Jamer<email:mikejamer@gmail.com")]
    [Trigger(TriggerText = "privmsg")]
    public sealed class PrivateMessageCommand : IrcAction {
        public override IrcSessionStates valid_states() {
            return IrcSessionStates.Connected | IrcSessionStates.Disconnected | IrcSessionStates.Registered;
        }

        public override void action(IrcSession session, IrcMessage message) {

            IrcEntity source = session.get_entity((string)session.Settings_Server[IrcServerSettings.NICKNAME]);
            IrcEntity dest = session.get_entity(message.Arguments[0]);

            IrcEvent privmsg_event = new IrcEvent(IrcEventTypes.PrivateMessage,
                new IrcEventArgument[] {
                    new IrcEventArgument(IrcEventArgumentType.SourceEntity, source),
                    new IrcEventArgument(IrcEventArgumentType.DestinationEntity, dest),
                    new IrcEventArgument(IrcEventArgumentType.Message, message.Arguments[1]),
                    new IrcEventArgument(IrcEventArgumentType.ArgumentsArray, message.Arguments)
                });

            session.send_raw(message.OriginalMessage); //Send raw command to server
            session.notify_event(privmsg_event); //handle this outgoing private message, the same way we handle incomming private messages
            return;
        }
    }
}
